import axios from 'axios'
import store from '../store/'
console.log('localStorage.Authorization——public', localStorage.Authorization)
let Authorization = localStorage.Authorization
//let Authorization = window.localStorage.Authorization 
//console.log('Authorization', Authorization)
axios.defaults.timeout = 10000
axios.defaults.headers.post['Content-Type'] = 'application/x-www=form-urlencoded'
axios.defaults.headers.Authorization = Authorization
axios.defaults.withCredentials=true; //withCredentials默认是false，意思就是不携带cookie信息，那就让它为true
axios.defaults.baseURL = 'http://pstsc.pstech360.com'
export default {
  fetchGet (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.get('/api'+url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  fetchPost (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.post('/api'+url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  fetchPut (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.put('/api'+url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  fetchDelete (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.delete('/api'+url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}
